package aip.core.dao.user;

import java.util.Set;

import org.springframework.dao.DataAccessException;
import org.springframework.util.StringUtils;

import com.googlecode.horncomb.bean.filter.ConditionSet;
import com.googlecode.horncomb.bean.filter.SimpleMapConditionSet;
import com.googlecode.horncomb.orm.ibatis.SqlMapEntityDaoImpl;
import aip.core.model.user.Expert;

/**
 * Expert data access object
 * <p>
 * 负责人/principal:<br/>
 * 修改记录/revision:<br/>
 * 日期:<br/>
 * 修改人:<br/>
 * 修改说明:<br/>
 * @author
 * @version $Id$
 */
public class ExpertDao extends SqlMapEntityDaoImpl<Expert>
{
    private static final long serialVersionUID = 650444571425854880L;

    @Override
    protected void insert(Object entity, String stmtName, String namespace)
            throws DataAccessException
    {
        stmtName = this.buildStatementName(namespace, StringUtils
                .hasText(stmtName) ? stmtName : this.insertStatementName);
        this.getSqlMapClientTemplate().insert(stmtName, entity);
    }

    public void deleteByUsernames(Set<String> usernames)
    {
        ConditionSet cons = new SimpleMapConditionSet().addConstraint(
                "usernames", usernames.toArray(new String[] {}));
        this.doDelete(cons, null);
    }

    public void deleteByUsername(String username)
    {
        ConditionSet cons = new SimpleMapConditionSet().addConstraint(
                "username", username);
        this.doDelete(cons, null);
    }
}
